package com.gdit.zax.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

public class SqlUtil {
	private static Map<String, String> sqlmap = new HashMap<String, String>();
	
	public static String getSql(String filename) {
		if (sqlmap==null)
			sqlmap = new HashMap<String, String>();
		String restring = sqlmap.get(filename);
		
		if (restring==null) {
			StringBuffer sb = new StringBuffer();
			try {
				InputStream in = SqlUtil.class.getResourceAsStream("/sql/"+filename);
				BufferedReader br = new BufferedReader(new InputStreamReader(in));
				String mresu;
				while ((mresu = br.readLine()) != null) {
					sb.append(mresu + " ");
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			
			restring =  sb.toString();
			sqlmap.put(filename, restring);
		}
//		LogUtil.print("sql:" + restring);
		return restring;

	}

}
